package com.shundr.shipper.common.view;

import android.app.DatePickerDialog;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;

public class MyDatePickerDialog extends DatePickerDialog {
	public MyDatePickerDialog(Context context, OnDateSetListener callBack,
			int year, int monthOfYear, int dayOfMonth) {
		super(context, callBack, year, monthOfYear, dayOfMonth);
		setTitle("请选择日期");
	}
	
	public void initView(boolean isYear,boolean isMonth,boolean isDay){
		DatePicker dp = findDatePicker((ViewGroup) this.getWindow().getDecorView());  
		if (dp != null) {
			if(!isYear){
				((ViewGroup)((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(0).setVisibility(View.GONE);
			}
			if(!isMonth){
				((ViewGroup)((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(1).setVisibility(View.GONE);
			}
			if(!isDay){
				((ViewGroup)((ViewGroup) dp.getChildAt(0)).getChildAt(0)).getChildAt(2).setVisibility(View.GONE);
			}
		} 
	}

	@Override
	public void onDateChanged(DatePicker view, int year, int month, int day) {
//		super.onDateChanged(view, year, month, day);
//		mDialog.setTitle(year + "年" + (month + 1) + "月");
		setTitle("请选择");
	}
	
	
	
	@Override
	protected void onStop() {
//		super.onStop();
	}

	private DatePicker findDatePicker(ViewGroup group) {  
        if (group != null) {  
            for (int i = 0, j = group.getChildCount(); i < j; i++) {  
                View child = group.getChildAt(i);  
                if (child instanceof DatePicker) {  
                    return (DatePicker) child;  
                } else if (child instanceof ViewGroup) {  
                    DatePicker result = findDatePicker((ViewGroup) child);  
                    if (result != null)  
                        return result;  
                }  
            }  
        }  
        return null;  
    }  
}
